class Product < ActiveRecord::Base

  self.per_page = 10

  validates :title, presence: true

  validates :description, presence: true

  validates :logo_img, presence: true

  has_many :photos, as: :photoable, dependent: :destroy

  mount_uploader :logo_img, ImageUploader

  scope :by_created_at_desc, -> { order('created_at desc') }

  scope :chinese, ->  { where(language: 1) }

  scope :english, -> { where(language: 2) }

  scope :traditional, ->  { where(language: 3) }

  scope :language, -> (language) { where(language: language) }

  self.primary_key = :id
end
